<template>
	<view>
		<view class="headForm">
			<u-form :model="formData" ref="uForm" label-width="160">
				<u-form-item label="船名/航次:" label-width="160">
					<u-input type="select" :select-open="shipShow" v-model="formData.ship"
						placeholder="请选择船名/航次" @click="shipShow = true"></u-input>
				</u-form-item> 
			</u-form> 
			<view class="btnGroup">
				<u-button :custom-style="customStyle" type="primary" @click="reset">重置</u-button>  
				<u-button :custom-style="customStyle" type="primary" @click="search">查询</u-button>  
			</view>
			
		</view>
		<view class="listCon">
			<view class="listItem" v-for="(item, index) in datalist" :key="index">
				<image v-if="item.file1 !== ''" style='width:750rpx;height:1000rpx;' :src="imgUrl+item.file1" @click="previewImage(item)"/>
				<image v-if="item.file2 !== ''" style='width:750rpx;height:1000rpx;' :src="imgUrl+item.file2" @click="previewImage(item)"/>													
				<image v-if="item.file3 !== ''" style='width:750rpx;height:1000rpx;' :src="imgUrl+item.file3" @click="previewImage(item)"/>																			
				<image v-if="item.file4 !== ''" style='width:750rpx;height:1000rpx;' :src="imgUrl+item.file4" @click="previewImage(item)"/>		
				<image v-if="item.file5 !== ''" style='width:750rpx;height:1000rpx;' :src="imgUrl+item.file5" @click="previewImage(item)"/>
			</view>
		</view>
		<u-select mode="single-column" :list="shipList" v-model="shipShow" @confirm="shipConfirm"
			value-name="id" label-name="shipname"  >
		</u-select>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				customStyle: {
					height: '60rpx',
				},
				shipList: [],
				datalist: [],
				imgUrl: 'https://api.zlkj-port.com/yqapi/ITally',
				shipShow: false,
				formData: {
					ship: '',
					shipid: ''
				},
				nickName: uni.getStorageSync("nickName")
			};
		},
		onLoad() {
			this.getOptions()
		},
		methods: {
			getOptions() {
				uni.request({
					url: 'https://api.zlkj-port.com/yqapi/ITally/xhtt/Q/ev5mqwCwjBv5Z2o?username=' + this.nickName,  //  admin
					method: 'get',
					success: (res) => {
						this.shipList = res.data.rows
					}
				})
			},
			search() {
				if(this.formData.ship !== '') {
					uni.request({
						url: 'https://api.zlkj-port.com/yqapi/ITally/xhtt/Q/QtGvWkekUGIJiEq',
						method: 'get',
						data: {
							shipid: this.formData.shipid
						},
						success: (res) => {
							this.datalist = res.data.rows
						}
					})
				} else {
					uni.showToast({
						title: '请先选择船名/航次',
						icon: 'none'
					})
				}
			},
			previewImage(item) {
				let fileList = []
				if(item.file1 !== '') {
					fileList.push(this.imgUrl + item.file1)
				}
				if(item.file2 !== '') {
					fileList.push(this.imgUrl + item.file2)
				}
				if(item.file3 !== '') {
					fileList.push(this.imgUrl + item.file3)
				}
				if(item.file4 !== '') {
					fileList.push(this.imgUrl + item.file4)
				}
				if(item.file5 !== '') {
					fileList.push(this.imgUrl + item.file5)
				}
				uni.previewImage({
					urls: fileList
				})
			},
			reset() {
				this.formData = {
					ship: '',
					shipid: ''
				}
			},
			shipConfirm(e){
				this.formData.ship = e[0].label
				this.formData.shipid = e[0].value
			}
		}
	}
</script>

<style lang="scss" scoped>
::v-deep .u-form-item {
		padding: 6rpx !important;
	}
	::v-deep .u-btn {
		height: 20px;
	}
.headForm {
		padding: 20rpx;
		position: fixed;
		width: 100%;
		top: 0;
		z-index: 10;
		background-color: #FFFFFF;

		.btnGroup {
			display: flex;
			justify-content: space-around;
			align-items: center;
			margin-top: 45rpx;
		}
	}
	.listCon {
		.listItem {
			padding-top: 150px;
			}
		}
</style>
